Skip to content

MQE-1884: MFTF - <after> failures override other failures #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 21, 2019
Merged

Conversation

soumyau
Copy link
Contributor

@soumyau soumyau commented Nov 14, 2019

attaching suppressed exception before _after hook failure to current step.

Description

Fixed Issues (if relevant)

  1. magento/magento2-functional-testing-framework#<issue_number>: Issue title
  2. ...

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/verification tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)
  • Changes to Framework doesn't have backward incompatible changes for tests or have related Pull Request with fixes to tests

attaching suppressed exception before _after hook failure to current step.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 53.621% when pulling 722f312 on MQE-1884 into 6c13d9d on develop.

@coveralls
Copy link

coveralls commented Nov 14, 2019

Coverage Status

Coverage decreased (-0.006%) to 53.612% when pulling d10be09 on MQE-1884 into 7f8fe40 on develop.

Copy link
Contributor

@KevinBKozan KevinBKozan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some feedback purely on the implementation side.

I think we need a little more time to test this. In the case of two comparison/errors I think we are good to go:
image

In the case of two broken steps, I do not think so, only the first broken step is injected into the test.

}
};
$firstException = $change->call($exception);
$bind = function () use ($firstException) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what 173~176 do. ExceptionWrapper.php does not have a variable named $exception, and at this point you already have the thing you need to log.

Is this leftover test flow or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the redundant code.

@KevinBKozan
Copy link
Contributor

On further experimentation, I am not sure I am seeing desired behavior with Codeception 2.4.0+:
image

bumped up codeception version to 2.4.5 to be inline with magento version. Removed method runAfterBlock, 2.4.5 runs _after hook implicitly.
@soumyau
Copy link
Contributor Author

soumyau commented Nov 18, 2019

Standalone mftf (codeception 2.3.9( doesn't seem to report broken steps correctly. After upgrading mftf to 2.4.5, standalone mftf reports:
Screen Shot 2019-11-18 at 12 16 51 PM
Screen Shot 2019-11-18 at 12 17 52 PM
Screen Shot 2019-11-18 at 12 18 23 PM
Screen Shot 2019-11-18 at 12 19 54 PM

* @param \Exception $exception
* @return mixed
*/
public function logPreviousException(\Exception $exception)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

  • Should we attach every exception, not just the buried one? It feels strange to see a test fail in two steps but only see one Exception attached. We could even label it Before/Test/After Exception using some functions in this class already.

Copy link
Contributor Author

@soumyau soumyau Nov 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were my initial thoughts too, but looks like After block's exception stack trace appears in the allure report twice - one at the top and another at the bottom after test steps. Will it be a duplication in some way? Capturing context and appending it to attachment name would work, however, there will only be 1 exception in Before + Test body scope, would context be redundant to display? Also looks like Allure doesn't show clear separation of Before/Test/After blocks of the test. What are your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good news is that with just Codeception 2.4.0 we can do a couple things:

  • Stop iterating over errors on line 88, they will only now be parent->previous() relationship
  • Given above, we can instead iterate by doing logError($error), wherein we log the parent, check for child and call logError($childError) to pop the full stack
  • remove the testFail() hook entirely, just use testEnd() to log these

We can modify the hook to look something like:

...
$testResultObject = call_user_func(\Closure::bind(
    function () use ($cest) {
        return $cest->getTestResultObject();
    },
    $cest
));
if (!empty($testResultObject->errors())) {
    foreach ($testResultObject->errors() as $error) {
        $this->attachExceptionToAllure($error->thrownException());
    }
}
if (!empty($testResultObject->failures())) {
    foreach ($testResultObject->failures() as $error) {
        $this->attachExceptionToAllure($error->thrownException());
    }
}
...

We can end up with something like this
image

You could add to the signature of attachExceptionToAllure to inlcude a prefix like Error vs Failure as well for clearer deliniation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we have some duplication, I think if we lean on prefixing the attachments it would be best in case someone needs the info. Those can be ignored by simply not expanding them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added context as a prefix to the attachment. Including a prefix like Error or Failure may need more investigation. From what I understood, PHPUnit\Framework\Exception are marked as failures and Magento\Framework\Exception are marked as Errors. Maybe there are exceptions which don't follow this criteria.
Screen Shot 2019-11-19 at 9 22 53 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right in not trusting that the exception types are necessarily linked to failure vs error. You could include them in the signature of your new attachExceptionToAllure but I think having the prefix is enough for now.

Attached stack trace of full stack of exceptions
Attachment name now has the test hook method in which the exception occured
Removed test fail method
Added mapping to contexts for allure attachments.
Copy link
Contributor

@KevinBKozan KevinBKozan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment on the internal ticket, check that out before merging please!

@soumyau soumyau merged commit 26ef6b0 into develop Nov 21, 2019
@soumyau soumyau deleted the MQE-1884 branch April 30, 2020 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants